package com.repeat.submit.utils;

import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @author : XiaGen
 * @Description: TODO
 * @date Date : 2021/11/25
 */
@AllArgsConstructor
public class RedisUtils {

   private RedisTemplate<String, String> redisTemplate;

   public boolean setNxKey(String key,String value,long s){
       return redisTemplate.opsForValue().setIfAbsent(key,value,s, TimeUnit.SECONDS);
   }

   public void deleteKey(String key,String value){
       String s = redisTemplate.opsForValue().get(key);
       if (value.equals(s)){
           redisTemplate.delete(key);
       }

   }
}
